package com.wandian.ui.controls
{

	//import mx.AnSense.ui.core.ui_internal;

	//use namespace ui_internal;

	public class ClassStyleDeclaration extends StyleDeclaration
	{
		public var className:String
		private var parent:ClassStyleDeclaration
		private var children:Array;
		private var next:ClassStyleDeclaration

		public function ClassStyleDeclaration(className:String, parent:ClassStyleDeclaration)
		{
			children=new Array();
			this.className=className;
			this.parent=parent;

		}

		override public function getStyle(key:String):*
		{
			var v:*
			if (styles != null)
			{
				v=styles[key];
			}
			return v != null ? v : next.getStyle(key)
		}

		public function addChild(child:ClassStyleDeclaration):void
		{
			children.push(child);
		}

		public function fixParentStylesRef():void
		{
			if (parent.styles == null)
			{
				if (parent.next == null)
				{
					parent.fixParentStylesRef()
				}
				next=parent.next
			}
			else
			{
				next=parent
			}
			trace(className + " fixParentStylesRef ");
		}

		public function notifyChildren(handler:String):void
		{
			for (var i:int=0; i < children.length; i++)
			{
				var csd:ClassStyleDeclaration=children[i]
				csd[handler]();
				csd.notifyChildren(handler);
			}
		}

	}
}
